﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StandUp.userControls;

namespace StandUp
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
            
            AssData.about Myabout = new AssData.about();
            this.labelProductName.Text = Myabout.AssemblyProduct;
            this.labelVersion.Text = String.Format("版本 {0} {0}", Myabout.AssemblyVersion);
            this.labelCopyright.Text = Myabout.AssemblyCopyright;
            this.labelCompanyName.Text = Myabout.AssemblyCompany;
            this.textBoxDescription.Text = Myabout.AssemblyDescription;
        }
        private void MainFrm_Load(object sender, EventArgs e)
        {
            eventList1.DateShowStart = mc_cc.SelectionStart;
            eventList1.DateShowEnd = mc_cc.SelectionStart.AddDays(1).AddSeconds(-1);
            pic_back.ImageLocation = Application.StartupPath + "\\res\\back_1.jpg";
            SetCarlendarPage();
        }
        AssData.GetChineseCalendar Mycc = new AssData.GetChineseCalendar();
        /// <summary>
        /// 获取主界面7天日期
        /// </summary>
        //void GetMainDate()
        //{
        //    lb_cc.Text = Mycc.GetChineseDateTime(DateTime.Now);
        //    for (int i = 1; i <= 7; i++)
        //    {
        //        foreach (System.Windows.Forms.Control ctr in tabPage1.Controls)
        //        {
        //            if (ctr.Name == "lb_date" + i.ToString())
        //            {
        //                ((Label)ctr).Text = DateTime.Now.AddDays(-3 + i).ToString("MM月dd日");
        //                continue;
        //            }
        //            if (ctr.Name == "lb_week" + i.ToString())
        //            {
        //                ((Label)ctr).Text = GetWeekStr(DateTime.Now.AddDays(-3 + i).DayOfWeek.ToString("D"));
        //                continue;
        //            }
        //        }
        //    }
        //    lb_cc.Text =Mycc.GetChineseMonth(DateTime.Now) + Mycc.GetChineseDay(DateTime.Now);
        //}
        /// <summary>
        /// 获取周几中文表示
        /// </summary>
        /// <param name="str"></param>
        string GetWeekStr(string str)
        {
            string[] week = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
            return week[int.Parse(str)];
        }
        void SetCarlendarPage()
        {
            DateTime cc = mc_cc.SelectionStart;
            lb_Ccy.Text = Mycc.GetChineseYear(cc)+" "+Mycc.GetChineseMonth(cc);
            lb_cpday.Text = Mycc.GetChineseDay(cc);
        }
        private MyWeibo WBFrm;
        /// <summary>
        /// 打开微博窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_weibo_Click(object sender, EventArgs e)
        {
            if (WBFrm == null || WBFrm.IsDisposed)//判断窗体是否存在实例，并且是否已经释放进程
            {
                WBFrm = new MyWeibo();
                WBFrm.StartPosition = FormStartPosition.Manual;
                WBFrm.Location = new Point(this.Location.X + 642, this.Location.Y);//设定弹窗的位置
                WBFrm.Show();
            }
            else
            {
                WBFrm.Activate();//如果窗体已存在则激活窗体给予焦点
            }
        }
        /// <summary>
        /// 设置日历详细信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mc_cc_MouseUp(object sender, MouseEventArgs e)
        {
            SetCarlendarPage();
        }

        private void MainFrm_SizeChanged(object sender, EventArgs e)
        {
            if (WindowState ==FormWindowState.Minimized)
            {
                this.Hide();
            }
        }

        private void 显示主界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.Activate();
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
                cms_notify.Show();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.Activate();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        AddEvent add;
        private void btn_addevent_Click(object sender, EventArgs e)//打开新建事件窗口
        {
            ShowAddWin();
        }
        /// <summary>
        /// 显示新事件
        /// </summary>
        private void ShowAddWin()
        {
            if (add == null || add.IsDisposed)
            {
                add = new AddEvent(-1);
                add.StartPosition = FormStartPosition.Manual;
                add.Location = new Point(this.Location.X + (Width - 388) / 2, (this.Location.Y + (Height - 441) / 2));
                add.ShowDialog(this);
                if (add.DialogResult == DialogResult.OK)
                    GetEventShow();
            }
            else
                add.Activate();
        }
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose(true); 
        }
        //根据日期查看事件
        private void mc_cc_DateChanged(object sender, DateRangeEventArgs e)
        {
            GetEventShow();
        }
        /// <summary>
        /// 显示事件列表
        /// </summary>
        public void GetEventShow()
        {
            eventList1.DateShowStart = mc_cc.SelectionStart;
            eventList1.DateShowEnd = mc_cc.SelectionStart.AddDays(1).AddSeconds(-1);
            eventList1.GetEvent();
        }

        private void 新事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowAddWin();
        }
        /// <summary>
        /// 后台进程监控
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_main_Tick(object sender, EventArgs e)
        {

        }

        #region 测试代码
        //void BuildList(DataTable dt)
        //{
        //    flowLayoutPanel1.Controls.Clear();
        //    _count = dt.Rows.Count;
        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        SingleEvents se = new SingleEvents();
        //        se.Name = "AutoSingleEvents" + i.ToString();
        //        se.Size = new System.Drawing.Size(431, 114);
        //        se.ID = int.Parse(dt.Rows[i][0].ToString());
        //        flowLayoutPanel1.Controls.Add(se);
        //    }
        //}
        //static int _count = 0;
        #endregion
    }
}
